package cn.dodgeball.java;

import cn.dodgeball.util.Const;

import javax.swing.*;
import java.awt.*;

public class BallPanel extends JPanel {
    public BallPanel(){
        setLayout(null);
        setOpaque(false);
        setBounds(0,0,Const.FRAME_WIDTH,Const.FRAME_HEIGHT);   //空间大小
        this.init();
    }

    public void init(){
        addBall();
    }

    public void clear(){
        for (Component component : getComponents()) {
            remove(component);
        }
        revalidate(); // 重新验证面板布局
        repaint(); // 重绘面板
    }

    private void addBall(){
        for(int i=0;i<Const.ballAccount;i++){
            Ball ball = new Ball();
            Thread thread=new Thread(ball);
            thread.start();
            this.add(ball);
        }
    }
}